<?php
namespace app\supermanager\controller;
use think\Controller;
use think\Session;
use think\Request;
/**
 * 企业动态管理
 */
class News extends \think\Controller
{   
    use \app\common\traits\controller\TraitController;
    /**
     * [FunctionName 企业动态列表]
     * @param string $value [description]
     */
    public function index()
    {
        $list = model('News')->getNewsInfoLists();//halt($list);
        $this->assign('list',$list);
        return view('news/index');
    }

    /**
     * GET show campgrade info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {

    }

    /**
     * GET shwo create campgrade info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('news/create');
    }

    /**
     * POST create new campgrade info
     * @return [type] [description]
     */
    public function save()
    {
        $post_news_info['title'] = input('post.title');
        $post_news_info['source'] = input('post.source');
        $post_news_info['author'] = input('post.author');
        $post_news_info['content'] = input('post.content');

        $count = model('News')->createNewsInfo($post_news_info);        

        if($count){
            return $this->success('添加文章成功','/news');
        }
            return $this->error('添加文章失败');
    }

    /**
     * GET edit campgrade info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $newsinfo = model('News')->getNewsInfo($id);
        $this->assign('newsinfo',$newsinfo);
        return view('news/edit');
    }

    /**
     * PUT update campgrade info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {
        $post_news_info['title'] = input('post.title');
        $post_news_info['source'] = input('post.source');
        $post_news_info['author'] = input('post.author');
        $post_news_info['content'] = input('post.content');
        
        $count = model('News')->updateNewsInfo($id, $post_news_info);

        if($count){
            return $this->success('修改文章成功','/news');
        }
            return $this->error('修改文章失败');
    }
    
    /**
     * DELETE campgrade info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete()
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('News')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/news');
        }
        return $this->error('删除失败');
    }

}
 ?>